package com.foreknow.elm.dao.impl;

import com.foreknow.elm.dao.OrderDetailetDao;
import com.foreknow.elm.po.OrderDetailet;
import com.foreknow.elm.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class OrderDetailetIDaompl implements OrderDetailetDao {
    private Connection conn;
    private PreparedStatement pst;
    private ResultSet rs;

    @Override
    public int save(OrderDetailet orderdetailet) throws SQLException {
        conn = DBUtil.getConnection();
        String sql = "insert into orderdetailet(orderId,foodId,quantity) values (?,?,?)";

        pst = conn.prepareStatement(sql);
        Integer orderid = orderdetailet.getOrderId();//null
        Integer foodid = orderdetailet.getFoodId();
        Integer quantity = orderdetailet.getQuantity();//null
        pst.setInt(1,orderid);
        pst.setInt(2,foodid);
        pst.setInt(3,quantity);
        int a = 0;
        try {
            a = pst.executeUpdate();
        }finally {
            DBUtil.close(pst);
        }

        return a;
    }
}
